package org.jetnuke.modules.pictures;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.jforum.dao.UserDAO;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.dao.PictureUserSettingsDAO;
import org.jetnuke.entities.PictureUserSettings;
import org.jetnuke.modules.pictures.utils.PictureUtils;

public class User implements IAction {
	int id;
	
	
	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {
		
		if(!PictureUtils.isPictureInitialized(id)){
			
			return new ActionForward(info,"no_pictures.vm");
		}
		net.jforum.entities.User usr=DataAccessDriver.getInst().newUserDAO().selectById(id);
		PictureUserSettingsDAO pusd=DataAccessDriver.getInst().newPictureUserSettingsDAO();
		PictureUserSettings pus=pusd.retrieveByPk(usr.getId());

		if(ui!=null && ui.getID()==id){
			vc.put("my_pictures",Boolean.TRUE);
		}
		vc.put("settings",pus);
		List preLeftBlocks=new ArrayList();
		List albums=DataAccessDriver.getInst().newPictureAlbumDAO().selectByUser(id);
		PictureUtils.manageStyle(pus,vc,preLeftBlocks);
		UserDAO um=DataAccessDriver.getInst().newUserDAO();
		net.jforum.entities.User user=um.selectById(id);
		vc.put("user",user);
		vc.put("user_albums",albums);

		preLeftBlocks.add(PictureUtils.createUserBlockInfo(vc,user));
		
		return new ActionForward(op,info);
	}
	public void setId(int id) {
		this.id = id;
	}

}
